Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Framework\Data\Collection::each() method #7330

Merged
merged 1 commit into from
May 25, 2017
Merged

Fix Framework\Data\Collection::each() method #7330

merged 1 commit into from
May 25, 2017

Conversation

Vinai
Copy link
Contributor

@Vinai Vinai commented Nov 6, 2016

The method \Magento\Framework\Data\Collection::each() sadly is completely broken, as it iterates over $args->_items instead of the collection items.
This PR add test coverage and fixes the method.

foreach ($args->_items as $k => $item) {
$args->_items[$k] = call_user_func($objMethod, $item);
foreach ($this->getItems() as $item) {
call_user_func_array([$item, $objMethod], $args);
Copy link
Contributor

@joshdifabio joshdifabio Nov 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call_user_func_array is quite slow compared to argument unpacking[1].

This should probably be changed to:

$item->$objMethod(...$args);

[1] https://gist.github.com/nikic/6390366

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, updated the PR.

@Vinai
Copy link
Contributor Author

Vinai commented Nov 20, 2016

Additional enhancement: in order to avoid surprising behavior allow passing a \Closure or an array callable [$obj, $method].

@Vinai
Copy link
Contributor Author

Vinai commented Nov 20, 2016

Unfortunately I can't make the tests pass because:

  • the integration tests are failing because the external third partx WebserviceX currency rate service is not reachable
  • The static test is failing because it dosn't process the argument unpacking syntax correctly (e.g. ->foo($item, ...$args) if the argument is not the only one. This means it is failing even though the code in the PR is PSR2 compliant.

To fix the integration tests they just need to be rerun at a different time when the service happens to be up and running, and to fix the static test the PSR2 code sniffer rule needs to be fixed.

@vrann vrann self-assigned this Mar 25, 2017
@vrann vrann added this to the March 2017 milestone Mar 25, 2017
@okorshenko okorshenko modified the milestones: March 2017, April 2017 Apr 2, 2017
@okorshenko okorshenko modified the milestones: April 2017, May 2017 May 9, 2017
@magento-team magento-team merged commit bb88d3d into magento:develop May 25, 2017
@magento-team
Copy link
Contributor

@Vinai thank you for your contribution to Magento 2 project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants